 import { clearAuth  } from '@/api/user';
 import Vue from 'vue'
 export const httpRequest = (url, data, method,isUser)=>{  //请求模块
    let token,session_id,userid,openid
    uni.showLoading({
        title: '加载中',
        mask:true,
        
    });
        try {
              session_id = uni.getStorageSync('session_id');
        } catch{
            
        }
        var p = new Promise(function(resolve, reject){
			data['debug']='-2'
            //初始化
            uni.request({
                url,
                data,
                method,
                header:{
                    'content-type': 'application/x-www-form-urlencoded',
					'Cookie':'PHPSESSID='+session_id,
					'observer':'OFF'
                },
                dataType: 'json',   
                success: (res) => {
					// #ifdef MP-BAIDU  
					if(res.data.tdk){
						Vue.prototype.$Shop.setStorage('tdk',JSON.stringify(res.data.tdk))
					}
					// #endif
                    //成功回调
					if(res.data.msg=='未登录！'||res.data.msg=='该方法用户名不能为空'){
						uni.showModal({
						   title: '提示',
						   content: '登录信息已过期或未登录',
						   confirmText:'立即登录',
						   cancelText:'匿名购买',
						   success: function (res) {
							   if (res.confirm) {
									uni.redirectTo({
									   url: '/pages/personal/login'
									}); 
							   } else if (res.cancel) { 
								   uni.reLaunch({
									  url: '/pages/index/index'
								   }); 
								   clearAuth();
							   }
						   }
					   });
					}else{
						resolve(res);
					}
                    uni.hideLoading();
                },
                fail: (res) => {
                    //失败回调
                    reject(res)
                }
            })
        });
        return p;
    }
